package com.tbit.uqbike.client.service.impl;

import com.tbit.uqbike.client.dao.log.ReturnBikeLogDao;
import com.tbit.uqbike.client.pojo.newEntity.ReturnBikeLog;
import com.tbit.uqbike.client.service.ReturnBikeLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @Author: chen
 * @Description:
 * @Date: 创建于 17:30 2021/12/23
 */
@Service
public class ReturnBikeLogServiceImpl implements ReturnBikeLogService {
    @Autowired
    private ReturnBikeLogDao returnBikeLogDao;

    @Override
    public void insert(ReturnBikeLog returnBikeLog) {
        returnBikeLog.setAddTime(new Date());
        returnBikeLogDao.insert(returnBikeLog);
    }

    @Override
    public void addBatch(List<ReturnBikeLog> list) {
        int i = list.size() % 500;
        int m = list.size() / 500;
        for (int j = 0; j < m; j++) {
            returnBikeLogDao.addBatch(list.subList(500 * j, 500 * (j + 1)));
        }
        if (i > 0) {
            returnBikeLogDao.addBatch(list.subList(500 * m, list.size()));
        }
    }
}
